package com.juc.threadPoolExecutor.threadPoolExecutor15.callerRunsPolicy;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class RunA {

	/**
	 * 
	 * CallerRunsPolicy:当任务添加到线程池中被拒绝时，会使用调用线程池的Thread
     * 线程对象处理被拒绝的任务 main线程被阻塞 不推荐MyThreadA
	 */
	public static void main(String[] args) {
		MyThreadA a = new MyThreadA();
		LinkedBlockingDeque<Runnable> queue  = new LinkedBlockingDeque<>(2);
		ThreadPoolExecutor executor = 
		new ThreadPoolExecutor(2, 3, 5, TimeUnit.SECONDS,queue, new ThreadPoolExecutor.CallerRunsPolicy());
		System.out.println("a begin " + Thread.currentThread().getName() +  "  "+ System.currentTimeMillis());
		executor.execute(a);
		executor.execute(a);
		executor.execute(a);
		executor.execute(a);
		executor.execute(a);
		executor.execute(a);
		System.out.println("a end " + Thread.currentThread().getName() +  "  "+ System.currentTimeMillis());

	}
}
